// Vue Router配置
import { createRouter, createWebHashHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import Dashboard from '../pages/Dashboard.vue';
import Settings from '../pages/Settings.vue';

// 定义路由
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Dashboard',
    component: Dashboard,
    meta: {
      title: '仪表板',
      icon: 'dashboard'
    }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: Settings,
    meta: {
      title: '设置',
      icon: 'settings'
    }
  }
];

// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(),
  routes
});

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `SideX - ${to.meta.title}`;
  }

  // 记录路由变化到控制台
  const fromName = from.name ? String(from.name) : 'unknown';
  const toName = to.name ? String(to.name) : 'unknown';
  console.log(`Navigating from ${fromName} to ${toName}`);

  next();
});

export default router;